home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
8174
/
8174.xpi
/
chrome
/
antbar.jar
/
content
/
grabber
/
queryobserver.js
< prev
Wrap
Text File
|
2009-12-30
|
6KB
|
185 lines
//
// queryobserver.js
// firefox
//
// Created by Zak on 2008-06-09.
// Copyright 2008-2009 Ant.com. All rights reserved.
//
/**
* Class: Observer called when firefox download something
* @constructor No parameters
*/
var AntQueryObserver = function ()
{
this.unvalidContentTypes = {
"application/x-shockwave-flash":1,
};
this.possibleContentTypes = {
"flv-application/octet-stream":1,
"application/octet-stream":1,
"text/plain":1,
"text/html":1
};
this.isValidContentLength = function (cl)
{
if (isNaN(cl) || cl < 500000)
return false;
return true;
};
this.regValidContentType = /video/,
this.isValidContentType = function (ct)
{
if (ct.match(this.regValidContentType))
return true;
return false;
};
/**
* Is this URL a junk URL ? From a ads for exemple
* @param url The URL to check
* @return boolean
*/
this.regForceNoJunk = /advert[0-9]*\.pornhub\.com/,
this.regJunk = /ads|advert|banner|doubleclick|visiblemeasures\.com|video-stats\.video\.google\.com|noflv|(info|widget)\.break\.com|diggthis/,
this.isJunkFlv = function (request)
{
if (this.unvalidContentTypes[request.contentType])
return true;
if (request.name.match(this.regForceNoJunk))
return false;
if (request.name.match(this.regJunk))
return true;
return false;
};
/**
* Is this URL a valid URL ? Assuming the content type as been checked first
* @param url The URL to check
* @return boolean
*/
this.regValidFlv = /flv|video|movie|film|clip|f4v|vod|mp4/,
this.isValidFlv = function (url)
{
return url.match(this.regValidFlv);
};
/**
* Is this URL the result of a seek in a player ?
* @param url The URL to check
* @return boolean
*/
// &fs=XXX => seek dailymotion
this.regSeekUrl = /[?&](st(art)?|begin|fs)=([1-9][0-9]*|0+[1-9]+)/i,
this.isSeekUrl = function (url)
{
return url.match(this.regSeekUrl);
};
/**
* Check if the given request is a valid flv file
* @param request The request object to authentify
* @return boolean True if the request is for a valid flv file, false instead
*/
this.isFlv = function (request)
{
if (this.isSeekUrl(request.name))
{
AntLib.toLog(request.name + " Rejected => Seek URL");
return false;
}
if (this.isJunkFlv(request))
{
AntLib.toLog(request.name + " Rejected => Junk");
return false;
}
if (this.isValidContentType(request.contentType))
{
AntLib.toLog(request.name + " Accepted => True Content & noJunk");
return true;
}
if (this.isValidContentLength(request.contentLength) &&
this.possibleContentTypes[request.contentType])
{
AntLib.toLog(request.name + " Accepted => validContentLength & possibleContentType & noJunk");
return true;
}
AntLib.toLog("Rejected => " + " url:" + request.name + " content-type:" + request.contentType);
return false;
};
this.getDocumentByRequest = function (request)
{
if (request.notificationCallbacks)
{
if (!(request.notificationCallbacks instanceof Components.interfaces.nsIDocShell))
return null;
try {
var interfaceRequestor = AntLib.QI(request.notificationCallbacks, AntLib.CI("nsIInterfaceRequestor"));
var win = AntLib.GI(interfaceRequestor, AntLib.CI("nsIDOMWindow"));
var currentDoc = win.document;
var rootDoc = currentDoc;
while (rootDoc.defaultView.frameElement)
rootDoc = rootDoc.defaultView.frameElement.ownerDocument;
return rootDoc;
}
catch (err) {
return null;
}
}
return null;
};
/**
* The function called by firefox, entry point of this class
* @param request The object containing the request params
* @param topic The specific event that trigger the function
* @param data the request data (seems to be empty)
*/
this.observe = function (request, topic, data)
{
var request = request.QueryInterface(Components.interfaces["nsIHttpChannel"]);
var doc = this.getDocumentByRequest(request);
// AntLib.toLog("Request.name = " + request.name + " do isNULL = " + (doc == null));
if (doc == null)
return;
if (this.isFlv(request))
{
var name = AntLib.safeGet(doc, "title");
AntLib.toLog("FLV NAME: " + name);
// FIXME: add score
var flvLink = new AntFlvLink({origin: AntLib.getSiteName(doc.location),
url: request.name,
name: name,
doc: doc,
type: request.contentType,
length: request.contentLength,
charset: request.contentCharset,
size: request.contentLength});
AntGrabber.foundFlvLink(flvLink);
}
};
}